package edu.gatech.gui;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;

import edu.gatech.datastorage.Invoice;
import edu.gatech.datastorage.TreatmentRecord;
import edu.gatech.presenters.InvoicePresenter;
import edu.gatech.userclasses.Patient;

public class InvoicePanel {
	private static JTextField textField;
	private static JTextField textField_1;
	private static JTextField textField_2;
	private static JTextField txtShots;
	private static JTextField txtXrays;
	private static JTextField txtRoutineCheckup;
	private static JTextField txtBloodWork;
	private static JTextField txtHeartSurgery;
	private static JTextField textField_8;
	private static JTextField textField_9;
	private static JTextField textField_10;
	private static JTextField textField_11;
	private static JTextField textField_12;
	private static JTextField textField_13;
	private static JTextField textField_14;
	private static JTextField textField_15;
	private static JTextField textField_16;
	private static JTextField textField_17;
	private static JTextField textField_18;
	private static JTextField textField_19;
	private static JTextField textField_20;
	private static JTextField textField_21;
	private static JTextField textField_22;
	private static TreatmentRecord currentRecord;
	private static Patient currentPatient;
	private static JFrame invoice;
	public InvoicePanel(TreatmentRecord record, Patient patient){
		currentRecord = record;
		currentPatient = patient;
		Invoice currentInvoice = record.getInvoice();
		invoice = new JFrame("Invoice Panel");
		
		MenuBar menuBar = new MenuBar(invoice);
		invoice.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        invoice.setSize(600,480); 
        invoice.getContentPane().setLayout(null);
        
        JLabel lblCurrentPatient = new JLabel("Current Patient:");
        lblCurrentPatient.setFont(new Font("Arial", Font.PLAIN, 9));
        lblCurrentPatient.setBounds(50, 53, 84, 14);
        invoice.getContentPane().add(lblCurrentPatient);
        
        JLabel label = new JLabel(currentPatient.getInfo().getName());
        label.setFont(new Font("Arial", Font.BOLD, 14));
        label.setBounds(50, 78, 171, 14);
        invoice.getContentPane().add(label);
        
        JLabel lblDateOfVisit = new JLabel("Date of Visit:");
        lblDateOfVisit.setFont(new Font("Arial", Font.PLAIN, 10));
        lblDateOfVisit.setBounds(284, 29, 84, 14);
        invoice.getContentPane().add(lblDateOfVisit);
        
        textField = new JTextField();
        textField.setEditable(false);
        textField.setText(record.getAppointment().toString());
        textField.setFont(new Font("Arial", Font.PLAIN, 10));
        textField.setBounds(376, 27, 120, 20);
        invoice.getContentPane().add(textField);
        textField.setColumns(10);
        
        JLabel lblDoctor = new JLabel("Attending Doctor:\r\n");
        lblDoctor.setFont(new Font("Arial", Font.PLAIN, 10));
        lblDoctor.setBounds(284, 66, 84, 14);
        invoice.getContentPane().add(lblDoctor);
        
        textField_1 = new JTextField();
        textField_1.setEditable(false);
        textField_1.setText(record.getDoctor());
        textField_1.setFont(new Font("Arial", Font.PLAIN, 10));
        textField_1.setBounds(376, 64, 120, 20);
        invoice.getContentPane().add(textField_1);
        textField_1.setColumns(10);
        
        JLabel lblServices = new JLabel("Service:\r\n");
        lblServices.setFont(new Font("Arial", Font.PLAIN, 10));
        lblServices.setBounds(66, 175, 46, 14);
        invoice.getContentPane().add(lblServices);
        
        JLabel lblAmountOwed = new JLabel("Amount Owed:");
        lblAmountOwed.setFont(new Font("Arial", Font.PLAIN, 10));
        lblAmountOwed.setBounds(284, 104, 76, 14);
        invoice.getContentPane().add(lblAmountOwed);
        
        textField_2 = new JTextField();
        textField_2.setFont(new Font("Arial", Font.PLAIN, 10));
        textField_2.setEditable(false);
        if(currentInvoice != null){
        	textField_2.setText("" + currentInvoice.getAmountOwed());
        }
        else{
        	textField_2.setText("$0.00");
        }
        textField_2.setColumns(10);
        textField_2.setBounds(376, 102, 120, 20);
        invoice.getContentPane().add(textField_2);
        
        JButton btnCalculate = new JButton("Calculate");
        btnCalculate.addActionListener(new ActionListener() {
        	public void actionPerformed(ActionEvent arg0) {
        		InvoicePresenter presenter = new InvoicePresenter(currentRecord);
        		presenter.calculate(textField_8.getText(), textField_11.getText(), 
        				textField_14.getText(), textField_17.getText(), textField_20.getText());
        		presenter.updateLabels(textField_2, textField_10, textField_13, textField_16, 
        				textField_19, textField_22);
        	}
        });
        btnCalculate.setFont(new Font("Arial", Font.PLAIN, 10));
        btnCalculate.setBounds(351, 360, 147, 23);
        invoice.getContentPane().add(btnCalculate);
        
        JLabel lblAmount = new JLabel("Quantity:");
        lblAmount.setFont(new Font("Arial", Font.PLAIN, 10));
        lblAmount.setBounds(284, 175, 46, 14);
        invoice.getContentPane().add(lblAmount);
        
        JLabel lblCost = new JLabel("Cost:");
        lblCost.setFont(new Font("Arial", Font.PLAIN, 10));
        lblCost.setBounds(351, 175, 46, 14);
        invoice.getContentPane().add(lblCost);
        
        JLabel lblTotal = new JLabel("Total:");
        lblTotal.setFont(new Font("Arial", Font.PLAIN, 10));
        lblTotal.setBounds(419, 175, 46, 14);
        invoice.getContentPane().add(lblTotal);
        
        txtShots = new JTextField();
        txtShots.setText("Shots");
        txtShots.setEditable(false);
        txtShots.setBounds(64, 209, 199, 20);
        invoice.getContentPane().add(txtShots);
        txtShots.setColumns(10);
        
        txtXrays = new JTextField();
        txtXrays.setText("X-rays");
        txtXrays.setEditable(false);
        txtXrays.setColumns(10);
        txtXrays.setBounds(64, 240, 199, 20);
        invoice.getContentPane().add(txtXrays);
        
        txtRoutineCheckup = new JTextField();
        txtRoutineCheckup.setText("Routine Check-up");
        txtRoutineCheckup.setEditable(false);
        txtRoutineCheckup.setColumns(10);
        txtRoutineCheckup.setBounds(64, 271, 199, 20);
        invoice.getContentPane().add(txtRoutineCheckup);
        
        txtBloodWork = new JTextField();
        txtBloodWork.setText("Blood work");
        txtBloodWork.setEditable(false);
        txtBloodWork.setColumns(10);
        txtBloodWork.setBounds(64, 302, 199, 20);
        invoice.getContentPane().add(txtBloodWork);
        
        txtHeartSurgery = new JTextField();
        txtHeartSurgery.setText("Heart surgery");
        txtHeartSurgery.setEditable(false);
        txtHeartSurgery.setColumns(10);
        txtHeartSurgery.setBounds(64, 333, 199, 20);
        invoice.getContentPane().add(txtHeartSurgery);
        
        textField_8 = new JTextField();
        if(currentInvoice != null){
        	textField_8.setText("" + currentInvoice.getShots());
        }
        else{
        	textField_8.setText("0");
        }
        textField_8.setBounds(284, 209, 57, 20);
        invoice.getContentPane().add(textField_8);
        textField_8.setColumns(10);
        
        textField_9 = new JTextField();
        textField_9.setText("40.00");
        textField_9.setEditable(false);
        textField_9.setColumns(10);
        textField_9.setBounds(351, 209, 57, 20);
        invoice.getContentPane().add(textField_9);
        
        textField_10 = new JTextField();
        if(currentInvoice != null){
        	textField_10.setText("" + currentInvoice.getTotalShots());
        }
        else{
        	textField_10.setText("$0.00");
        }
        textField_10.setEditable(false);
        textField_10.setColumns(10);
        textField_10.setBounds(419, 209, 79, 20);
        invoice.getContentPane().add(textField_10);
        
        textField_11 = new JTextField();
        if(currentInvoice != null){
        	textField_11.setText("" + currentInvoice.getXrays());
        }
        else{
        	textField_11.setText("0");
        }
        textField_11.setColumns(10);
        textField_11.setBounds(284, 240, 57, 20);
        invoice.getContentPane().add(textField_11);
        
        textField_12 = new JTextField();
        textField_12.setText("100.00");
        textField_12.setEditable(false);
        textField_12.setColumns(10);
        textField_12.setBounds(351, 240, 57, 20);
        invoice.getContentPane().add(textField_12);
        
        textField_13 = new JTextField();
        if(currentInvoice != null){
        	textField_13.setText("" + currentInvoice.getTotalXrays());
        }
        else{
        	textField_13.setText("$0.00");
        }
        textField_13.setEditable(false);
        textField_13.setColumns(10);
        textField_13.setBounds(419, 240, 79, 20);
        invoice.getContentPane().add(textField_13);
        
        textField_14 = new JTextField();
        if(currentInvoice != null){
        	textField_14.setText("" + currentInvoice.getCheckUps());
        }
        else{
        	textField_14.setText("0");
        }
        textField_14.setColumns(10);
        textField_14.setBounds(284, 271, 57, 20);
        invoice.getContentPane().add(textField_14);
        
        textField_15 = new JTextField();
        textField_15.setText("50.00");
        textField_15.setEditable(false);
        textField_15.setColumns(10);
        textField_15.setBounds(351, 271, 57, 20);
        invoice.getContentPane().add(textField_15);
        
        textField_16 = new JTextField();
        if(currentInvoice != null){
        	textField_16.setText("" + currentInvoice.getTotalCheckUps());
        }
        else{
        	textField_16.setText("$0.00");
        }
        textField_16.setEditable(false);
        textField_16.setColumns(10);
        textField_16.setBounds(419, 271, 79, 20);
        invoice.getContentPane().add(textField_16);
        
        textField_17 = new JTextField();
        if(currentInvoice != null){
        	textField_17.setText("" + currentInvoice.getBloodWork());
        }
        else{
        	textField_17.setText("0");
        }
        textField_17.setColumns(10);
        textField_17.setBounds(284, 302, 57, 20);
        invoice.getContentPane().add(textField_17);
        
        textField_18 = new JTextField();
        textField_18.setText("40.00");
        textField_18.setEditable(false);
        textField_18.setColumns(10);
        textField_18.setBounds(351, 302, 57, 20);
        invoice.getContentPane().add(textField_18);
        
        textField_19 = new JTextField();
        if(currentInvoice != null){
        	textField_19.setText("" + currentInvoice.getTotalBloodWork());
        }
        else{
        	textField_19.setText("$0.00");
        }
        textField_19.setEditable(false);
        textField_19.setColumns(10);
        textField_19.setBounds(419, 302, 79, 20);
        invoice.getContentPane().add(textField_19);
        
        textField_20 = new JTextField();
        if(currentInvoice != null){
        	textField_20.setText("" + currentInvoice.getSurgery());
        }
        else{
        	textField_20.setText("0");
        }
        textField_20.setColumns(10);
        textField_20.setBounds(284, 333, 57, 20);
        invoice.getContentPane().add(textField_20);
        
        textField_21 = new JTextField();
        textField_21.setText("100000");
        textField_21.setEditable(false);
        textField_21.setColumns(10);
        textField_21.setBounds(351, 333, 57, 20);
        invoice.getContentPane().add(textField_21);
        
        textField_22 = new JTextField();
        if(currentInvoice != null){
        	textField_22.setText("" + currentInvoice.getTotalSurgery());
        }
        else{
        	textField_22.setText("$0.00");
        }
        textField_22.setEditable(false);
        textField_22.setColumns(10);
        textField_22.setBounds(419, 333, 79, 20);
        invoice.getContentPane().add(textField_22);
        
        JPanel panel = new JPanel();
        panel.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null), "Invoice Information", TitledBorder.LEADING, TitledBorder.TOP, null, UIManager.getColor("Button.darkShadow")));
        panel.setBounds(21, 129, 539, 265);
        invoice.getContentPane().add(panel);
        
        JButton btnDone = new JButton("Done");
        btnDone.addActionListener(new ActionListener() {
        	public void actionPerformed(ActionEvent arg0) {
        		invoice.hide();
        	}
        });
        btnDone.setBounds(450, 409, 89, 23);
        invoice.getContentPane().add(btnDone);
        invoice.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        invoice.setSize(600,500); 
        invoice.setVisible(true);
	}
}
